<!-- 包含下个版本迭代的余额调整新加的内容, 包含Customer_Blance -->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
      class="globalSerchFormStyle"
    >
      <el-row :gutter="50">
        <el-col :span="6" v-if="$store.state.user.userLevel === null">
          <el-form-item label="油企名称" prop="stationId">
            <el-select
              v-model="queryParams.stationId"
              placeholder="请选择油企"
              size="small"
              filterable
              clearable
              style="width: 190px"
            >
              <el-option
                v-for="(item, index) in enterpriseList2"
                :key="index"
                :label="item.enterpriseName"
                :value="item.enterpriseId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户姓名" prop="blogNickName">
            <el-input
              v-model="queryParams.blogNickName"
              placeholder="请输入客户姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 200px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="联系电话" prop="mobilePhone">
            <el-input
              v-model="queryParams.mobilePhone"
              placeholder="请输入"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 200px"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="余额" prop="minBalance">
            <el-input
              v-model="queryParams.minBalance"
              placeholder="请输入"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 200px"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="50">
        <el-col :span="6">
          <el-form-item label="注册时间">
            <el-date-picker
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
              size="small"
              v-model="dateValue"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              :picker-options="pickerOptions"
              align="right"
              @change="changeDatePicker"
              @focus="focusDatePicker"
              style="width: 215px"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="会员编码" prop="memberCode">
            <el-input
              v-model="queryParams.memberCode"
              placeholder="请输入会员编码"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
              style="width: 200px"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="global_el_rowStyle">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          plain
          >重置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:user:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5" v-if="$store.state.user.userLevel === null">
        <el-button
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefresh"
          :disabled="!queryParams.stationId"
          :loading="refreshLoading"
        >
          刷新
        </el-button>
      </el-col>
    </el-row>

    <!-- 汇总数据  -->
    <el-row class="members-margin">
      <el-col :span="5">
        <span>
          <span class="members-size">会员总数量：</span>
          <span class="number-size"> {{ appUserSum }} </span>
          <span class="members-colour">个</span>
        </span>
      </el-col>
      <el-col :span="6">
        <span>
          <span class="members-size">{{ timePeriod }}新增会员数量：</span>
          <span class="number-size"> {{ newUserNumber }} </span>
          <span class="members-colour">个</span>
        </span>
      </el-col>
    </el-row>

    <el-table :data="manageList" stripe v-loading="tableLoading">
      <!-- <af-table-column label="会员id" align="left" prop="userId" /> -->
      <af-table-column label="会员编码" align="left" prop="memberCode" />
      <!-- <af-table-column
        label="会员推送id"
        show-overflow-tooltip
        align="left"
        prop="blogOpenid"
      /> -->
      <af-table-column label="油企" align="left" prop="enterpriseName" />
      <!-- <af-table-column label="会员等级" align="left">
        <template slot-scope="scope">
          {{ scope.row.memberLevel === "1" ? "普卡" : "" }}
          {{ scope.row.memberLevel === "2" ? "银卡" : "" }}
          {{ scope.row.memberLevel === "3" ? "金卡" : "" }}
          {{ scope.row.memberLevel === "4" ? "钻卡" : "" }}
          {{ scope.row.memberLevel === "5" ? "黑卡" : "" }}
        </template>
      </af-table-column> -->
      <!-- <af-table-column label="来源" align="left" prop="source" /> -->
      <!-- <af-table-column label="姓名" align="left" prop="name" /> -->
      <!-- <af-table-column label="性别" align="left" prop="sexFlag">
        <template slot-scope="scope">
          <span v-if="scope.row.sexFlag === 'W'">女</span>
          <span v-if="scope.row.sexFlag === 'M'">男</span>
          <span v-if="scope.row.sexFlag === '2'">女</span>
          <span v-if="scope.row.sexFlag === '1'">男</span>
        </template>
      </af-table-column> -->
      <!-- <af-table-column label="生日" align="left" prop="birthday" /> -->
      <af-table-column label="昵称" align="left" prop="blogNickName" />
      <af-table-column label="手机号" align="left" prop="mobilePhone" />
      <!-- <af-table-column label="车牌号码" align="left" prop="truckNumber" /> -->
      <!-- <af-table-column label="IC卡号" align="left" prop="ICCard" /> -->
      <af-table-column label="电子卡总余额(元)" align="left" prop="balance" />
      <af-table-column label="积分余额" align="left" prop="integral" />

      <af-table-column label="成长值" align="left" prop="growUpValue" />

      <af-table-column
        label="注册时间"
        align="left"
        prop="registeDate"
        sortable
      />
      <!-- <af-table-column label="更新时间" align="left" prop="updateDate" /> -->
      <!-- <af-table-column
        label="首次消费的油站"
        align="left"
        prop="firstStationName"
      /> -->
      <!-- <af-table-column
        label="常用油品id"
        align="left"
        prop="usualOilName"
        sortable
      /> -->
      <af-table-column label="unid" align="left" prop="unionId" v-if="false" />
      <af-table-column label="操作" align="left" fixed="right" width="250px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="couponView(scope.row)">
            查看
          </el-button>
          <el-button
            v-if="['1', '2'].includes($store.state.user.userLevel)"
            size="mini"
            type="text"
            @click="consumption(scope.row)"
          >
            消费扣款
          </el-button>
          <!-- <el-button size="mini" type="text" @click="deduction(scope.row)">
            消费扣款
          </el-button> -->
          <el-dropdown style="margin-left: 10px">
            <el-button class="el-dropdown-link" type="text" size="mini">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  @click="resetPassword(scope.row)"
                >
                  重置密码
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  @click="showBalance(scope.row)"
                >
                  余额查询
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  @click="couponSearch(scope.row)"
                >
                  优惠券查询
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  @click="recordQuery(scope.row)"
                >
                  充值查询
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  @click="orderQuery(scope.row)"
                >
                  订单查询
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="text"
                  v-if="scope.row.yunhuaUserId === null"
                  @click="sendYunHua(scope.row)"
                >
                  补充回调
                </el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </af-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看客户订单信息 -->
    <el-dialog
      :title="titleOrderInfo"
      :visible.sync="openOrderInfo"
      width="40%"
      append-to-body
    >
      <el-table :data="orderList" style="width: 100%">
        <af-table-column
          label="油站"
          align="left"
          prop="stationName"
          sortable
          width="100%"
        />
        <af-table-column label="订单号" align="left" prop="orderNo" sortable width="100%"/>
        <af-table-column
          label="油品名称"
          align="left"
          prop="oilName"
          sortable
          width="100%"
        />
        <af-table-column
          label="油品价格"
          align="left"
          prop="oilPirce"
          sortable
          width="100%"
        />
        <af-table-column
          label="加油升数"
          align="left"
          prop="orderLiters"
          sortable
          width="100%"
        />
        <af-table-column label="应收金额" align="left" prop="receivableAmt" sortable width="100%" />
        <af-table-column label="实付金额" align="left" prop="amt" sortable width="100%" />
        <af-table-column label="立减优惠" align="left" prop="discountAmt" sortable width="100%" />
        <af-table-column label="优惠券优惠金额" align="left" prop="discountCouponAmt" sortable width="150%" />
        <af-table-column
          label="消费者昵称"
          width="120"
          align="left"
          prop="consumer"
        />
        <af-table-column
          label="加油员"
          width="120"
          align="left"
          prop="oilPersonnel"
        />
        <af-table-column label="加油枪号" align="left" prop="oilGun" />
        <af-table-column
          label="支付类型"
          align="left"
          prop="payType"
          :formatter="payTypeFotmat"
        />
        <af-table-column
          label="油站名称"
          width="120"
          align="left"
          prop="stationName"
          v-if="false"
        />
        <af-table-column
          label="用户id(消费者)"
          align="left"
          prop="consumerId"
          v-if="false"
        />
        <af-table-column
          label="油站id"
          align="left"
          prop="stationId"
          v-if="false"
        />
        <af-table-column
          label="支付完成时间"
          align="left"
          prop="payDate"
          width="160"
        >
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.payDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
        <af-table-column
          label="订单创建时间"
          align="left"
          prop="createdDate"
          width="160"
        >
          <template slot-scope="scope">
            <span>{{
              parseTime(scope.row.createdDate, "{y}-{m}-{d} {h}:{i}:{s}")
            }}</span>
          </template>
        </af-table-column>
      </el-table>
      <pagination
        v-show="totalOrder > 0"
        :total="totalOrder"
        :page.sync="queryOrder.pageNum"
        :limit.sync="queryOrder.pageSize"
        @pagination="listPage"
      />
    </el-dialog>

    <!-- 查看客户充值记录 -->
    <el-dialog
      :title="titleUseRecord"
      :visible.sync="openUserRecord"
      width="700px"
      append-to-body
    >
      <el-table :data="useRecordList">
        <af-table-column label="油站" align="left" prop="stationName" />
        <af-table-column label="订单号" align="left" prop="orderNo" />
        <af-table-column label="充值金额" align="left" prop="amt" />
        <af-table-column
          label="消费者昵称"
          width="120"
          align="left"
          prop="customerName"
        />
        <af-table-column
          label="充值时间"
          align="left"
          prop="createTime"
        ></af-table-column>
      </el-table>
      <pagination
        v-show="totalOrder > 0"
        :total="totalOrder"
        :page.sync="queryRecord.pageNum"
        :limit.sync="queryRecord.pageSize"
        @pagination="listRecordPage"
      />
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
      style=""
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox
            v-model="upload.updateSupport"
          />是否更新已经存在的用户数据
          <el-link type="info" style="font-size: 12px" @click="importTemplate"
            >下载模板</el-link
          >
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入“xls”或“xlsx”格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitFileForm"
          :loading="uploadLoading"
          >确 定</el-button
        >
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 余额查询 -->
    <CustomerBlance
      :showBalanceDrawer.sync="showBalanceDrawer"
      :currenRowData="currenRowData"
      @reloadData="getList"
    ></CustomerBlance>

    <!-- 消费扣款抽提 -->
    <Deduction
      :deductionExtraction.sync="deductionExtraction"
      :enterpriseList="enterpriseList"
      :consumerId="consumerId"
      :listWithOilDatas="listWithOilDatas"
      :stationIds="stationIds"
    ></Deduction>

    <!-- 优惠价查询 -->
    <CouponSearch
      style="margin-top: 20px"
      :couponsInfo="couponsInfo"
      :dialogTableVisible.sync="dialogTableVisible"
    ></CouponSearch>

    <!-- 查看 -->
    <CouponView
      :couponsInfo="couponsInfo"
      :deductionView.sync="deductionView"
    ></CouponView>

    <!-- 新消费扣款 -->
    <CouponDeduction
      :couponsInfo="couponsInfo"
      :dialogDeduction.sync="dialogDeduction"
    ></CouponDeduction>
  </div>
</template>

<script>
import { timeComparison } from "@/utils/timeConversion";
import {
  listManage,
  getOrderInfo,
  getUseRecord,
  sendToYunHua,
  importTemplate,
  importData,
  cardUserList,
  updateUserRecord,
  exportList,
  numberMembers,
  updateUserMemberCodeApi,
  restPasswordApi,
} from "@/api/customer/manage";
import { getEnterpriseList } from "@/api/dept";
import { stationinfo } from "@/api/station/gun";
import { listPrice } from "@/api/station/price";
import { getToken } from "@/utils/auth";
import { listEnterpriseStation } from "@/api/dept";
import CustomerBlance from "./Customer_Blance.vue";
import { cloneDeep } from "lodash";
import Deduction from "./Customer_deduction.vue";
import { listWithOil } from "@/api/customer/info";
import CouponSearch from "./Customer_CouponSearch.vue";
import CouponView from "./Customer_CouponView.vue";
import CouponDeduction from "./Customer_CouponDeduction.vue";
import vue from "vue";

export default {
  name: "Customer_Info",
  components: {
    CustomerBlance,
    Deduction,
    CouponSearch,
    CouponView,
    CouponDeduction,
  },
  data() {
    const that = this;
    return {
      uploadLoading: false,
      // 新消费扣款
      dialogDeduction: false,
      // 优惠价查询
      couponsInfo: "",
      dialogTableVisible: false,
      // 查看
      deductionView: false,

      stationIds: "",
      listWithOilDatas: [],
      testTitle: "测试",
      // 总条数
      total: 0,
      totalOrder: 0,
      // 客户管理表格数据
      manageList: [],
      orderList: [],
      useRecordList: [],
      // 是否显示弹出层
      openOrderInfo: false,
      openUserRecord: false,
      titleOrderInfo: "",
      titleUseRecord: "",
      oilNameOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        minBalance: null,
        customerName: null,
        // commendMan: null,
        // memberGrade: null,
        mobilePhone: null,
        // oilName: null,
        // levelId: this.levelId,
        beginTime: null,
        endTime: null,
        memberCode: null,
      },

      // 会员数量查询参数
      member: {
        beginTime: null,
        endTime: null,
      },

      sendParam: {
        userId: null,
        mobilePhone: null,
      },
      queryOrder: {
        pageNum: 1,
        pageSize: 10,
        oilName: null,
        stationId: null,
        consumerId: null,
      },
      queryRecord: {
        pageNum: 1,
        pageSize: 10,
        stationId: null,
        mobilePhone: null,
        userId: null,
        unionId: null,
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/appUserInfo/info/importData",
      },

      showBalanceDrawer: false, // 余额查询弹框
      currenRowData: {},
      // balanceList: [],
      // cardUseRangeFlag: "",
      // balanceDetailsList: [],
      // isDetails: false,
      // totalBalance: 0,
      // showAdjust: false,
      // customerCardChangeDto: {},
      // cardChangeRules: {
      //   stationId: [
      //     { required: true, message: "请选择油站", trigger: "change" },
      //   ],
      //   amt: [
      //     {
      //       required: true,
      //       message: "请选择输入调整后的余额",
      //       trigger: "change",
      //     },
      //   ],
      // },
      // stationList: [],

      // 注册时间选择数据
      dateValue: null,
      timePeriod: "今日",
      timePeriodNew: "今日",

      pickerOptions: {
        shortcuts: [
          {
            text: "今日",
            onClick: (picker) => {
              this.timePeriodNew = "今日";
              const end = new Date();
              const start = new Date(new Date().toLocaleDateString());
              start.setTime(start.getTime());
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "昨日",
            onClick: (picker) => {
              this.timePeriodNew = "昨日";
              const today = new Date();
              today.setHours(0);
              today.setMinutes(0);
              today.setSeconds(0);
              today.setMilliseconds(0);
              const end = new Date(today - 1000);
              const start = new Date(today - 3600 * 1000 * 24);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "近七日",
            onClick: (picker) => {
              this.timePeriodNew = "近七日";
              const today = new Date();
              today.setHours(0);
              today.setMinutes(0);
              today.setSeconds(0);
              today.setMilliseconds(0);
              const end = new Date();
              const start = new Date(today - 3600 * 1000 * 24 * 6);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "本月",
            onClick: (picker) => {
              this.timePeriodNew = "本月";
              const end = new Date();
              const start = new Date();
              start.setDate(1);
              start.setHours(0);
              start.setSeconds(0);
              start.setMinutes(0);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      newUserNumber: 0,
      appUserSum: 0,

      // 消费扣款抽提隐藏显示数据
      deductionExtraction: false,

      // 油站列表
      enterpriseList: [],
      // 会员id
      consumerId: null,
      enterpriseId2: null,
      enterpriseList2: [],
      refreshLoading: false,
      tableLoading: false,
    };
  },
  created() {
    this.queryParams.beginTime = null;
    this.queryParams.endTime = null;
    this.getNumberMembers();
    this.getList();
    this.getEnterpriseListQuery();
  },
  methods: {
    // 点击新消费扣款
    consumption(row) {
      this.couponsInfo = row;
      this.dialogDeduction = true;
    },
    // 点击查看
    couponView(row) {
      this.couponsInfo = row;
      this.deductionView = true;
      console.log("点击查看", row);
    },
    // 点击优惠价查询
    couponSearch(row) {
      this.couponsInfo = row;
      this.dialogTableVisible = true;
    },
    // 查询油企
    getEnterpriseListQuery() {
      getEnterpriseList().then((res) => {
        this.enterpriseList2 = res.rows;
      });
    },
    // 余额查询
    showBalance(row) {
      // this.isDetails = false;
      this.showBalanceDrawer = true;
      this.currenRowData = cloneDeep(row);
    },

    /** 导出按钮操作 */
    handleExport() {
      if (!this.queryParams.stationId)
        return this.$message.warning("请选择油企");
      const queryParams = this.queryParams;

      // const time = timeComparison(
      //   30,
      //   "export",
      //   queryParams.beginTime,
      //   queryParams.endTime
      // );
      // if (!time) return;

      this.$confirm("是否确认导出所有用户数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return exportList(queryParams);
        })
        .then((response) => {
          this.downloadFile(response.msg);
        });
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then((response) => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
      this.uploadLoading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.uploadLoading = false;
      const tip = `<div style="height:60vh; overflow-y: auto;">${response.msg}</div>`;
      this.$alert(tip, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    payTypeFotmat(row, column) {
      if (row.payType === "sxf") {
        return "随行付";
      } else if (row.payType === "dzk") {
        return "电子卡";
      } else if (row.payType === "wx") {
        return "微信";
      } else if (row.payType === "zfb") {
        return "支付宝";
      } else if (row.payType === "xj") {
        return "现金";
      }
    },
    statusFotmat(row, column) {
      if (row.status === "0") {
        return "未支付";
      } else if (row.status === "1") {
        return "已支付";
      }
    },
    /** 查询客户管理列表 */
    getList() {
      this.tableLoading = true;
      // this.queryParams.levelId = this.levelId

      // const time = timeComparison(
      //   30,
      //   "earching",
      //   this.queryParams.beginTime,
      //   this.queryParams.endTime
      // );
      // if (!time) return (this.tableLoading = false);

      listManage(this.queryParams)
        .then((response) => {
          this.tableLoading = false;
          this.manageList = response.rows;
          this.total = response.total;
        })
        .catch((err) => {
          this.tableLoading = false;
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.getNumberMembers();
      this.getList();
      this.updataMemberPass();
      // this.updataMember();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateValue = null;
      this.queryParams.beginTime = null;
      this.queryParams.endTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
      this.timePeriod = "今日";
      this.timePeriodNew = "今日";
    },

    // 操作消费扣款
    //打开
    deduction(row) {
      this.deductionExtraction = true;
      this.Judgment();
      this.consumerId = row.userId;
      // console.log("操作消费扣款按钮函数", row);
    },

    orderQuery(row) {
      this.queryOrder.consumerId = row.userId;
      this.listPage();
    },
    recordQuery(row) {
      this.queryRecord.userId = row.userId;
      this.queryRecord.mobilePhone = row.mobilePhone;
      this.queryRecord.unionId = row.unionId;
      this.listRecordPage();
    },
    listPage() {
      getOrderInfo(this.queryOrder).then((response) => {
        this.orderList = response.rows;
        this.openOrderInfo = true;
        this.totalOrder = response.total;
        this.titleOrderInfo = "查看客户订单信息";
      });
    },
    listRecordPage() {
      getUseRecord(this.queryRecord).then((response) => {
        this.useRecordList = response.rows;
        this.openUserRecord = true;
        this.totalOrder = response.total;
        this.titleUseRecord = "查看客户充值记录";
      });
    },

    sendYunHua(row) {
      this.sendParam.mobilePhone = row.mobilePhone;
      this.sendParam.userId = row.userId;
      sendToYunHua(this.sendParam).then((response) => {
        if (response.code == 200) {
          this.getList();
        } else {
          throw new Error("");
        }
      });
    },

    // 获取日期
    getTim() {
      let nowTime = {
        beginTime: "",
        endTime: "",
      };
      const date = new Date();
      //年
      const year = date.getFullYear();
      //月
      const month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      //日
      const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      //时
      const hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      //分
      const mm =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      //秒
      const ss =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

      nowTime.beginTime =
        year + "-" + month + "-" + day + " " + "00" + ":" + "00" + ":" + "00";

      nowTime.endTime =
        year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss;
      return nowTime;
    },

    // 查询会员数量和总会员量
    async getNumberMembers() {
      let totalMembers;
      if (this.dateValue === null) {
        this.member.endTime = this.getTim().endTime;
        this.member.beginTime = this.getTim().beginTime;
      } else {
        this.member.endTime = this.queryParams.endTime;
        this.member.beginTime = this.queryParams.beginTime;
      }
      totalMembers = await numberMembers(this.member);
      this.newUserNumber = totalMembers.newUserNumber;
      this.appUserSum = totalMembers.appUserSum;
    },

    // 用户确认了时间范围点击了确认按钮
    changeDatePicker() {
      if (this.dateValue === null) {
        this.queryParams.beginTime = null;
        this.queryParams.endTime = null;
      } else {
        this.queryParams.beginTime = this.dateValue[0];
        this.queryParams.endTime = this.dateValue[1];
      }
    },

    // 获取焦点
    focusDatePicker() {
      this.$nextTick(() => {
        const buttonA = document.getElementsByClassName(
          "el-picker-panel__footer"
        )[0];
        const buttonB = buttonA.childNodes;
        buttonB[1].addEventListener("click", () => {
          console.log(111, this.timePeriodNew);
          this.timePeriodNew = "所选时间内";
        });
      });
    },

    // 更改日期
    updataMemberPass() {
      if (this.dateValue) {
        this.timePeriod = this.timePeriodNew;
      } else {
        this.timePeriod = "今日";
      }
    },

    //获取油站，this.presentEnterprise.enterpriseId
    // status 油站的状态 : 1 正常, 0 停用
    Judgment() {
      listEnterpriseStation({
        enterpriseId:
          this.presentEnterprise && this.presentEnterprise.enterpriseId,
        status: "1",
      }).then((res) => {
        this.enterpriseList = res;
        // 判断单站，多站
        if (res.length > 1) {
          this.listWithOilDatas = [];
          this.stationIds = "";
          // console.log("判断多站res.length <= 1", res);
        } else if (res.length === 1) {
          this.stationIds = res[0].stationId;
          // 获取员工
          listWithOil({ stationId: res[0].stationId }).then((res) => {
            this.listWithOilDatas = res.data;
            // console.log("油站获取员工列表", res);
          });
          // console.log("判断单站res.length === 1", res);
        }
      });
    },

    // 刷新按钮
    async handleRefresh() {
      // this.queryParams.stationId  因为搜索哪里的接口传的叫stattionId，但是拿的值却是enterpriseId
      const enterpriseId = this.queryParams.stationId;
      this.refreshLoading = true;
      await updateUserMemberCodeApi({ enterpriseId });
      this.refreshLoading = false;
      this.handleQuery();
    },

    // 重置密码
    resetPassword(row) {
      console.log(row);
      let username = "";
      let text = "";
      if (row.blogNickName) {
        username = row.blogNickName;
        text = "";
      } else {
        username = row.userId;
        text = "会员ID为 ";
      }
      this.$confirm(`确认重置${text}${username}会员的密码吗`).then(async () => {
        await restPasswordApi(row.userId);
        this.msgSuccess("重置密码成功");
        this.getList();
      });
    },
  },
  watch: {
    dialogDeduction: {
      deep: true, // 深度监听
      handler(newVal, oldVal) {
        if (!newVal) return this.handleQuery();
      },
    },
  },
};
</script>
<style scoped lang="scss">
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>
